<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php //echo $commander->getListCommandsPanel('n-sa-a-d-ad_types-ad_cats-pager-filter', ''); ?>
<?php //echo $commander->getListCommandsPanel('ad_types-ad_cats', ''); ?>
<?php //echo $commander->getListCommandsPanel('jqGridSave', ''); ?>
<?php /* 
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
		<thead class="fields">
			<tr>
				<th class="first center">&nbsp;&nbsp;Id&nbsp;&nbsp;</th>
				<th class="nosort"><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></th>
				<th><?php echo ucfirst($txt->getWord('title')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('ad_type')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('ad_category')); ?></th>
				<th><?php echo ucfirst($txt->getWord('active')); ?></th>
				<th class="last nosort"><?php echo ucfirst($txt->getWord('delete')); ?></th>
			</tr>
		</thead>
		<tbody>
		</tbody> 
	</table>
</div> */?>
<table id="object-list">
</table>
<div id="object-list-pager"></div>

<div id="add_dialog" title="<?php echo ucfirst($txt->getWord('new').' '.$txt->getWord('brand')); ?>?" style="display:none; text-align:left;">
	<p> <?php echo ucfirst($txt->getWord('title')); ?>
		<input class="small" name="new_item_title" type="text" value="" maxlength="80" id="new_item_title" />
		<br />
	</p>
</div>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('ad_type')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete')); ?></p>
</div>
<script type="text/javascript">
function addNewDialog(itemId)
{
	jQuery('#add_dialog').dialog('open');
	jQuery('#add_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('add')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					new_item_title: jQuery('#new_item_title').val()} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function deleteDialog(itemId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete')).' '.$txt->getWord('ad_type'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					del_item_id: itemId} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function loadItems()
{
	var typeId = <?php echo intval($_REQUEST['typeId']); ?>;
	var catId = <?php echo intval($_REQUEST['catId']); ?>;
	var getUrl = 'ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>';
	
	if($("#typeId").val() > 0)
	{ 
		typeId = $("#typeId").val();
		getUrl = getUrl + '&typeId='+typeId;
	}
	if($("#catId").val() > 0)
	{ 
		catId = $("#catId").val();
		getUrl = getUrl + '&catId='+catId;
	}
	
	/*
	jQuery('table.item_list tbody').empty();
	jQuery('table.item_list tbody').html('<?php echo $commander->getComponentListLoading(); ?>'); 
	jQuery.ajax(
	{
		url: getUrl,
		cache: false,
	  	success: function(html)
	  	{ 
			jQuery('table.item_list tr.loading').remove();
			jQuery("table.item_list tbody").append(html); 
			jQuery("#menulist").addClass('tablesorter');
			jQuery("#menulist").tablesorter(
				{
					widthFixed: true,  
					headers: { 0: { sorter: 'numeric' }, 1: { sorter: false}, 5: {sorter: false}, 6: {sorter: false} }, 
					sortList: [[0,0]],
					textExtraction: function(node) { return node.innerHTML; }
				}).tablesorterPager(
				{
					container: jQuery("div.pager")
				}).tablesorterFilter(
				{
					filterContainer: $("#filter-box"),
					filterClearContainer: $("#filter-clear-button"),
					filterWaitTime: 100,
					filterColumns: [1],
					filterCaseSensitive: false
				});
		}
	});
	*/
	var lastsel2;
	jQuery("#object-list").jqGrid(
	{ 
		url:'json.php<?php echo $commander->getFormAction('ajax'); ?>&q=<?php echo $_REQUEST['q']; ?>',
		datatype: "json", 
		prmNames: 
		{
			page:"page",
			rows:"ipp", 
			sort: "sidx",
			order: "sord", 
			search:"q", 
			nd:"nd", 
			id:"brandId",
			oper:"oper",
			editoper:"edit",
			addoper:"add",
			deloper:"del", 
			subgridid:"id", 
			npage: null, 
			totalrows:"totalrows"
		},
		colNames:
		[
		 	'Id',
			'<?php echo ucfirst($txt->getWord('title')); ?>', 
			'<?php echo ucfirst($txt->getWord('description')); ?>',
			'<?php echo ucfirst($txt->getWord('ad_type')); ?>', 
			'<?php echo ucfirst($txt->getWord('ad_category')); ?>',
			'<?php echo ucfirst($txt->getWord('active')); ?>'
		], 
		colModel:
		[ 
			{name:'brandId', index:'Id', width:55}, 
			{name:'Title', index:'title', width:200, editable:true, editoptions:{size:"20", maxlength:"100"}},
			{
				name:'Description',
				index:'Description', 
				width:400,
				align:"left", 
				sortable:false, editable: true, edittype:"textarea", editoptions:{rows:"8",cols:"34"}
			}, 
			{
				name:'TypeId',
				index:'TypeId', 
				width:200, 
				editable: true, 
				edittype:"select", 
				editoptions:
				{
					value:"<?php 
					echo '0:'.ucfirst($txt->getWord('all')).';';
					if($adc->getAdTypes())
					{
						foreach($adc->getAdTypes() as $type)
						{ echo $type->getId().':'.$type->getTitle().';'; }
					}
					?>"
				}
			},
			{
				name:'CatId',
				index:'CatId', 
				width:300, 
				editable: true, 
				edittype:"select", 
				editoptions:
				{
					value:"<?php 
					echo '0:'.ucfirst($txt->getWord('all')).';';
					if($adc->getAdCats())
					{
						foreach($adc->getAdCats() as $cat)
						{ echo $cat->getId().':'.$cat->getTitle().';'; }
					}
					?>"
				}
			},
			{
				name:'Active',
				index:'Active', 
				width:80,
				editable: true, 
				edittype:"select",  
				editoptions:
				{
					value:"<?php 
					echo '0:'.ucfirst($txt->getWord('no')).';';
					echo '1:'.ucfirst($txt->getWord('yes')).';';
					?>"
				}
			}
		],
		pager: '#object-list-pager',
		viewrecords: true, 
		rowNum:<?php echo $adc->Pager->getItemsPerPage(); ?>,
		width:800,
		height: "100%",
		autosearch:true,
		caption:"",
		rownumbers: true, 
		editurl: "json.php<?php echo $commander->getFormAction('ajax'); ?>",
		pager: '#object-list-pager'
	}); 
	//jQuery("#object-list").jqGrid('navGrid','#object-list-pager',{edit:false, add:true, del:true});
	
	jQuery("#object-list").jqGrid('navGrid',"#object-list-pager",{edit:false,add:false,del:false}); 
	jQuery("#object-list").jqGrid('inlineNav',"#object-list-pager");
	jQuery("#object-list").jqGrid('filterToolbar',
	{
		stringResult: false, 
		searchOnEnter : true
	});
}

jQuery(document).ready(function() 
{ loadItems(); });
</script>
